/**
 * react 17等版本使用，react18会导致服务无法访问
const proxy = require('http-proxy-middleware')

module.exports = function (app) {
  app.use(
    proxy('/api1', {
      target: 'http://localhost:5000',
      pathRewrite: {
        '^/api1': ''
      },
      changeOrigin: true
    })
  )
}
 */

/**
 * react18
 */
const { createProxyMiddleware } = require('http-proxy-middleware')
module.exports = function (app) {
  app.use(
    createProxyMiddleware('/api1', { // 遇见/api1前缀请求，就会触发该代理配置
      target: 'http://localhost:5000', // 请求转发给谁
      pathRewrite: {  
        '^/api1': ''
      },
      changeOrigin: true // 控制服务器收到的响应头中Host字段的值
    }),
    createProxyMiddleware('/api2', {
      target: 'http://localhost:5001',
      pathRewrite: {
        '^/api2': ''
      },
      changeOrigin: true
    })
  )
}
